import { Component } from "@angular/core";
import { NavController,App } from 'ionic-angular';
import { NativeStorage } from '@ionic-native/native-storage';
import { HttpClient } from '@angular/common/http'
import { TranslateService } from '@ngx-translate/core';

import { AppConfig } from '../../app/app.config';

import { PostlistPage } from './postlist/postlist';
import { WalletPage } from './wallet/wallet';
import { VerifyPage } from './verify/verify';
import { ResetPage } from './reset/reset';
import { SetPage } from './set/set';
import { PaypwdPage } from "./paypwd/paypwd";
import { MyPage } from "./my/my";
import { CheckPage } from "../messages/check/check"

@Component({
    selector: 'page-more',
    templateUrl: 'more.html',
})
export class MorePage {
    postPage = PostlistPage;
    walletPage = WalletPage;
    verifyPage = VerifyPage;
    resetPage = ResetPage;
    setPage = SetPage;
    checkPage = CheckPage;
    paypwdPage = PaypwdPage;
    myPage = MyPage;
    dependentColumns  = [
        {
          options: [
            { text: 'Chinese', value: 'ch' },
            { text: 'English', value: 'en' },
            // { text: 'Spanish', value: 'sp' },
          ]
        }
    ];
    default="en"
    user={
        firstname:'',
        avatar:'',
        level:'',
    }
    level=1;
    src:any
    pushData:any
    constructor(
        public navCtrl: NavController,
        public app:App,
        private stroge:NativeStorage,
        private http:HttpClient,
        private translate: TranslateService
    ) {
        this.src = AppConfig.getMainUrl()
        translate.setDefaultLang('en')
    }
    ionViewDidEnter(){
        this.stroge.getItem('lang').then(res=>{
            this.default = res
            this.translate.use(res)
        })
        this.stroge.getItem('token').then(token=>{
            this.http.get(AppConfig.getUrl()+'user/getInfo?token='+token).subscribe(res=>{
                if(res['code']==101){
                    this.user = res['data']
                }
            })
        })
        this.stroge.getItem('level').then(res=>{
            this.level =res
        })
    }
    _level(item){
        let str = ''
        switch(item){
            case 1:
                str = 'Member'
                break
            case 2:
                str = 'Agent'
                break
            case 3:
                str = 'Service provider'
                break
        }
        return str
    }
    picker(){
        this.stroge.setItem('lang',this.default)
        this.translate.use(this.default)
    }
    goto(page:any){
        this.app.getRootNav().push(page,{
            userInfo:this.user,
            callback: data => {
                this.user.firstname = data.firstname;
                this.user.avatar = data.avatar;
            }
        })
    }
}